<?php

namespace App\Providers;

use App\Model\wx\WxOrder;
use App\Services\UtilService;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();
    }

    /**
     * Define the routes for the application.
     *
     * @return void
     */
    public function map()
    {
//        $this->mapApiRoutes();
        $this->mapWchatApiRoutes();
//        $this->mapCcjkApiRoutes();
    }

    protected function mapApiRoutes()
    {
        Route::group([
            'middleware' => 'api',
            'namespace' => $this->namespace,
        ], function ($router) {
            require base_path('routes/api.php');
        });
    }

//    protected function mapCcjkApiRoutes()
//    {
//
//        if (UtilService::getInstance()->isOnline()) {
//            $prefix = "api/ccjk";
//        } else {
//            $prefix = "api/ccjk-test";
//        }
//        Route::group([
//            'middleware' => 'api',
//            'namespace' => $this->namespace,
//            'prefix' => $prefix
//        ], function ($router) {
////            require base_path('routes/ccjk_api.php');
//            require base_path('routes/base_api.php');
//        });
//    }

    protected function mapWchatApiRoutes()
    {
        $platform = env("PLATFORM");//co3,ccjk
        WxOrder::checkPlatform($platform);
        $prefix = "api/$platform";
//        if (UtilService::getInstance()->isOnline()) {
//            $prefix = "api/$platform";
//        } else {
//            $prefix = "api/$platform-test";
//        }
        Route::group([
            'middleware' => 'api',
            'namespace' => $this->namespace,
            'prefix' => $prefix
        ], function ($router) {
//            require base_path('routes/co3_api.php');
            require base_path('routes/base_api.php');
        });
    }


}
